package DS0626;

public class SeqLists {
    private static int max = 20;
    private Student arr[] = new Student[max];
    private int len = 0 ;
    //简单直插
    public void insert(Student date){
        arr[len] = date;
        len++;
    }
    //指定位置插入
    public void insert(int position, Student student){
        if(position > len){
            System.out.println("您插入的位置不合法");
            return;
        }
        for(int i = len-1 ; i>=position ; i--){
            arr[i+1] = arr[i];
        }
        arr[position] = student;
        len++;

    }
    //长度
    public int length(){
        return len;
    }

    //实现删除给定姓名的学生的方法
    public void delStudent(Student student){
        for(int i=0 ; i<len ; i++){
            if(arr[i].equals(student)){
                for(int j =i ; i<len-1 ; i++){
                    arr[j] = arr[ j+1];
                }
                len--;
            }
        }
    }
    //打印
    public void display(){
        for(int i=0; i<len; i++){
            System.out.print(arr[i] +" ");
        }
        System.out.println();
    }
}
